package Client;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws Exception{
        Socket socket = new Socket("localhost",10086);
        DataInputStream dis = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
        DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
        Scanner scanner = new Scanner(System.in);
        boolean flag = false;
        while(!flag){
            System.out.println("请输入正方形边长：");
            double lengtn = scanner.nextDouble();
            dos.writeDouble(lengtn);
            dos.flush();
            double area = dis.readDouble();
            System.out.println("服务器返回的面积是："+area);
            while(true){
                System.out.println("继续计算？（Y/N）");
                String str = scanner.next();
                if(str.equalsIgnoreCase("N")){//不区分大小写
                    dos.writeInt(0);
                    dos.flush();
                    flag = true;
                    break;
                }else if(str.equalsIgnoreCase("Y")){
                    dos.writeInt(1);
                    dos.flush();
                    break;
                }
            }
        }
        socket.close();
    }

}
